package com.invengo.module_check.ui.fragment.search;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.navigation.fragment.NavHostFragment;

import com.afollestad.materialdialogs.MaterialDialog;
import com.invengo.base.excel.ExportExcelUtils;
import com.invengo.library_db.entity.module_check.BookBean;
import com.invengo.module_check.BR;
import com.invengo.module_check.R;
import com.invengo.module_check.databinding.FragmentSearchBookBinding;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseApplication;
import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class BookSearchFragment extends BaseFragment<FragmentSearchBookBinding, BookSearchViewModel> {
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_search_book;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
    }

    @Override
    public String getRightTitle() {
        return "导出结果";
    }


    private MaterialDialog inportDialog;

    @Override
    public void onRightEvent(View view) {
        List<BookBean> beans = viewModel.getUnfindList();
        if (beans.size() == 0) {
            ToastUtils.showShort("暂无未找到图书列表");
            return;
        }
        ExportExcelUtils.getInstance().exportUnfindCollect(getActivity(),beans);
    }

    @Override
    public BookSearchViewModel initViewModel() {
        BookSearchViewModel bookSearchViewModel = super.initViewModel();
        BaseApplication application = (BaseApplication) getActivity().getApplication();
        application.setPubViewModel(bookSearchViewModel);
        return bookSearchViewModel;
    }

    @Override
    public void initViewObservable() {
        viewModel.ui.addBookEvent.observe(this, integer -> NavHostFragment.findNavController(BookSearchFragment.this).navigate(R.id.bookSearchFragment_2_addBookFragment));
    }
}
